<template>
  <div>
    <div id="header">
      <div id="box">
        <div class="header-top">
          <ul class="left">
            <li>尚品汇欢迎您！</li>
            <li v-if="!nickName">
              请
              <router-link to="/login">登录</router-link
              >&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;
              <router-link to="/register">免费注册</router-link>
            </li>
            <li v-else>
              <span>{{ nickName }}</span>
              <button @click="cancellation">注销</button>
            </li>
          </ul>
          <ul class="right">
            <li><router-link to="/">我的订单</router-link></li>
            <li><router-link to="/shopCart">我的购物车</router-link></li>
            <li><a href="#">我的尚品汇</a></li>
            <li><a href="#">尚品汇会员</a></li>
            <li><a href="#">企业采购</a></li>
            <li><a href="#">关注尚品汇</a></li>
            <li><a href="#">合作招商</a></li>
            <li><a href="#" class="last">商家后台</a></li>
          </ul>
        </div>
      </div>
      <div class="header-bottom">
        <router-link to="/" class="logo">
          <img src="./logo.b2878689.png" alt="logo" />
        </router-link>
        <div class="bottom-right">
          <form action="GET" @submit.prevent="SubmitTo" class="from">
            <input type="text" v-model="keyword" />
            <button type="submit">搜索</button>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "Header",
  data() {
    return {
      keyword: "",
    };
  },
  methods: {
    SubmitTo() {
      let keyword = this.keyword;
      //定义一个对象
      let cearchObj = {
        name: "Search",
      };
      cearchObj.query = this.$route.query;
      //判断输入框是否有值
      if (keyword) {
        cearchObj.params = { keyword };
      }
      this.$router.history.push(cearchObj);
    },
    cancellation() {
      localStorage.removeItem("user");
      location.reload();
    },
  },
  computed: {
    ...mapState("Login", ["nickName", "token"]),
  },
};
</script>

<style scoped>
#box {
  background-color: rgba(234, 234, 234, 0.6);
}
.header-top {
  display: flex;
  margin: auto;
  width: 1200px;
  justify-content: space-between;
  line-height: 30px;
}
.header-bottom {
  display: flex;
  justify-content: space-between;

  width: 1200px;
  line-height: 70px;
  margin: auto;
}
.header-bottom .logo {
  display: flex;
  align-items: center;
}

li {
  margin: 0 5px;
}
.left,
.right {
  display: flex;
  justify-content: space-between;
}
.right li a {
  border-right: 1px solid #333;
  padding-right: 5px;
}
.last {
  border: none !important;
}
.from {
  height: 70px;
  display: flex;
  align-items: center;
}
.bottom-right input {
  width: 500px;
  height: 30px;
  border: 1px solid orange;
  outline: none;
  font-size: 16px;
  opacity: 0.4;
}
.bottom-right button {
  width: 80px;
  height: 34px;
  outline: none;
  border: 1px solid orange;
  background-color: orange;
  opacity: 0.4;
}
.bottom-right button:active {
  color: aliceblue;
}
</style>